﻿<script type="text/javascript">
    var PArray = "";
    var count = 1;
    var coo = count;
    function showPreview(source) {
        if (!isPicFile(source)) {
            alert("您选择的文件中有非图片文件");
            source.outerHTML = source.outerHTML;//清空file的value
            return false;
        }
        source.style.display = 'none';
        var co;
        var cooo = count;
        var picSrc = "" + co + "" + "img";
        for (co = coo - 1; source.files[co] != null; co++) {
            var div = document.getElementById("divMain");
            var img1 = document.createElement("div");
            img1.style.width = "20%";
            img1.style.float = "left";
            img1.innerHTML = "<img display='' id='" + cooo + "'  style='width:100%;height:150px;border-color:black;border:2px;border-style:dashed;' onclick='clickImage(this)' />";
            divMain.appendChild(img1);
            var img = document.getElementById("" + cooo + "");
            img.src = window.URL.createObjectURL(source.files[co]);
            cooo++;
            count++;
        }
        var Picfile = document.createElement("div");
        Picfile.style.width = "20%";
        Picfile.style.float = "left";
        Picfile.innerHTML = "<input type='file' id='" + picSrc + "' multiple='multiple' style='width:100%;' name='files' value='继续选择照片'  onchange='showPreview(this)' />";
        divMain.appendChild(Picfile);
    }
    function isPicFile(filename) {
        for (var countFile = 0; filename.files[countFile] != null; countFile++) {
            var file1 = filename.files[countFile];
            if (file1.type == "image/jpeg" || file1.type == "image/png") {
            }
            else {
                return false;
            }
        }
        return true;
    }
    function clickImage(Img) {
        PArray = PArray + Img.id + "/";
        //alert(PArray);
        Img.style.display = 'none';
    }
    function clickSub() {
        document.getElementById("txt1").value = PArray;
        if (document.getElementById("AlbumName").value == "" || document.getElementById("AlbumType").value == "") {
            alert("请在每个输入框输入合法内容");
            return 0;
        }
        document.getElementById("formMain").submit();
    }
</script>
<body>
    <div id="divMain">
        <input type="file" id="0img" multiple="multiple" style="width:100%;" name="files" value="选择照片" onchange="showPreview(this)" />

    </div>
</body>
